package org.lee.datasource.service;

import org.lee.datasource.bean.User;
import org.lee.datasource.configuration.TargetDataSource;
import org.lee.datasource.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lizhe
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserService {

    @Autowired
    private UserMapper mapper;

//    @TargetDataSource("slave")
    public User getUser(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

//    @TargetDataSource("master")
    public int addUser(User user){
        return mapper.insert(user);
    }
}
